﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceModel;
using WCFMINERP.Contracts.InterFaces;

using WCFMINERP.COM;
namespace WCFMINERP.Update
{
    public partial class FrmNewUser : Form
    {
        public FrmNewUser()
        {
            InitializeComponent();
        }
        ChannelFactory<IShop> _proxyShop;//创建代理
        IShop ishop;
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtPwd.Text != txtPwdToo.Text)
            {
                MessageBox.Show("两次输入密码不一致请确认");
                return;
            }
            _proxyShop = new ChannelFactory<IShop>("IShop");
            ishop = _proxyShop.CreateChannel();
            try
            {
                int rtnVal = ishop.RegisterNewUser(txtUsername.Text.Trim(), Md5HashCode.GetHash(txtPwd.Text), txtSHACODE.Text);
                
                if (rtnVal == 0)//正常注册
                {
                    Properties.Settings.Default.SHACODE = txtSHACODE.Text;
                    Properties.Settings.Default.Save();
                    MessageBox.Show("恭喜注册成功");
                    this.Close();
                   
                }
                else if (rtnVal == 1)//已经注册过
                {
                    MessageBox.Show("该注册码已经使用不能重复使用");
                }
                else if (rtnVal == -2)
                {
                    MessageBox.Show("注册码无效");
                }
                else if (rtnVal == -3)
                {
                    MessageBox.Show("用户名重复");
                }
                else//注册出错
                {
                    MessageBox.Show("过程出错，请稍候再试");
                }
                
            }
            catch
            {
                MessageBox.Show(Properties.Settings.Default.ServerName+"服务器未连接");
            }

        }

        private void txtPwdToo_Leave(object sender, EventArgs e)
        {
            if (txtPwd.Text != txtPwdToo.Text)
            {
                MessageBox.Show("两次输入密码不一致请确认");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txtPwd_EditValueChanged(object sender, EventArgs e)
        {

        }
    }
}
